package com.e3.web.core.model;

import java.util.Date;

import com.extjs.gxt.ui.client.data.BaseModelData;

public class SuperModel extends BaseModelData implements SuperModelFields {

	private static final long serialVersionUID = 6212114608275708387L;
	
	private final static String MODEL_ID = "MODEL_ID";

	public Long getId() {
		return getLongValue(SuperModelFields.ID);
	}

	public void setId(Long id) {
		set(SuperModelFields.ID, id);
		if(getModelId()==null||getModelId().length()==0){
			setModelId(id+"");
		}
	}
	
	public void setModelId(String id){
		set(MODEL_ID,id);
	}
	
	public String getModelId(){
		return get(MODEL_ID);
	}

	public Long getCreateUserId() {
		return get(SuperModelFields.CREATE_USER_ID);
	}

	public void setCreateUserId(Long createUserId) {
		set(SuperModelFields.CREATE_USER_ID, createUserId);
	}

	public Date getCreateTime() {
		return get(SuperModelFields.CREATE_TIME);
	}

	public void setCreateTime(Date createTime) {
		set(SuperModelFields.CREATE_TIME, createTime);
	}

	public Long getModifyUserId() {
		return get(SuperModelFields.MODIFY_USER_ID);
	}

	public void setModifyUserId(Long modifyUserId) {
		set(SuperModelFields.MODIFY_USER_ID, modifyUserId);
	}

	public Date getModifyTime() {
		return get(SuperModelFields.MODIFY_TIME);
	}

	public void setModifyTime(Date modifyTime) {
		set(SuperModelFields.MODIFY_TIME, modifyTime);
	}
	
	public Long getCorpId() {
		return getLongValue(SuperModelFields.CORP_ID);
	}

	public void setCorpId(Long corpId) {
		set(SuperModelFields.CORP_ID, corpId);
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (!(obj instanceof SuperModel)) {
			return false;
		}

		SuperModel model = (SuperModel) obj;

		if (model.getId().equals(this.getId())) {
			return true;
		}
		return false;
	}

	public double getDoubleValue(String name){
		return getDoubleValue(name,0.0);
	}
	
	public long getLongValue(String name){
		return getLongValue(name, 0L);
	}
	
	public int getIntValue(String name){
		return getIntValue(name,0);
	}
	
	public boolean getBooleanValue(String name){
		return getBooleanValue(name, false);
	}
	
	public double getDoubleValue(String name,double nullValue){
		return get(name,nullValue);
	}
	
	public long getLongValue(String name,long nullValue){
		String id = String.valueOf(get(name,0L));
		return Long.parseLong(id);
	}
	
	public int getIntValue(String name,int nullValue){
		String value = String.valueOf(get(name,0));
		return Integer.parseInt(value);
	}
	
	public boolean getBooleanValue(String name,boolean nullValue){
		return get(name,nullValue);
	}
	
	public long getRefModelId(String name){
		SuperModel model = (SuperModel)get(name);
		if(model != null){
			return model.getId();
		}
		return 0L;
	}
}
